import {Component, OnInit} from '@angular/core';
import {MdDialog} from '@angular/material';
import {NewTaskComponent} from '../new-task/new-task.component';
import {CopyTaskComponent} from '../copy-task/copy-task.component';
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
import {NewTaskListComponent} from '../new-task-list/new-task-list.component';

@Component({
  selector: 'app-task-home',
  templateUrl: './task-home.component.html',
  styleUrls: ['./task-home.component.scss']
})
export class TaskHomeComponent implements OnInit {

  lists = [
    {
      id: 1,
      name: '代办',
      tasks: [
        {
          id: 1,
          desc: '任务一:喝咖啡',
          priority: 1,
          completed: false,
          owner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-1',
          },
          dueDate: new Date(),
          reminder: new Date(),
        },
        {
          id: 2,
          desc: '任务二:写作业,然后尽情的去dota2',
          priority: 2,
          completed: true,
          owner: {
            id: 1,
            name: '李四',
            avatar: 'avatars:svg-2'
          },
          dueDate: new Date()
        },
      ]
    },
    {
      id: 2,
      name: '正在办理',
      completed: false,
      tasks: [
        {
          id: 1,
          desc: '任务一',
          priority: 3,
          owner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-10'
          },
          dueDate: new Date()
        },
        {
          id: 2,
          desc: '任务二',
          priority: 3,
          completed: true,
          owner: {
            id: 1,
            name: '李四',
            avatar: 'avatars:svg-12'
          },
          dueDate: new Date()
        },
      ]
    },
    {
      id: 3,
      name: '已完成',
      tasks: [
        {
          id: 1,
          desc: '任务一',
          priority: 3,
          owner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-10'
          },
          dueDate: new Date()
        },
        {
          id: 2,
          desc: '任务二',
          priority: 3,
          completed: true,
          owner: {
            id: 1,
            name: '李四',
            avatar: 'avatars:svg-12'
          },
          dueDate: new Date()
        },
      ]
    },
  ];

  constructor(private dialog: MdDialog) {
  }

  ngOnInit() {
  }

  launchNewTaskDialog() {
    this.dialog.open(NewTaskComponent, {data: {title: '新增任务'}});
  }

  launchCopyTaskDialog() {
    const copyTaskComponentMdDialogRef = this.dialog.open(CopyTaskComponent, {data: {lists: this.lists}});
  }

  launchUpdateTaskItem(task) {
    const copyTaskComponentMdDialogRef = this.dialog.open(NewTaskComponent, {data: {title: '更新任务', task: task}});
  }

  launchEditTaskNameDialog() {
    const copyTaskComponentMdDialogRef = this.dialog.open(NewTaskListComponent, {data: {title: '更新列表标题'}});
    copyTaskComponentMdDialogRef.afterClosed().subscribe(result => console.log(result));
  }

  launchDelDialog() {
    const delResult = this.dialog.open(ConfirmDialogComponent, {data: {title: '删除任务列表', content: '是否要删除该任务列表?'}});
    delResult.afterClosed().subscribe(result => console.log(result));
  }

  openNewTaskListDialog() {
    const openNewTaskListDialogRef = this.dialog.open(NewTaskListComponent, {data: {title: '新增任务列表'}});
    openNewTaskListDialogRef.afterClosed().subscribe(result => console.log(result));
  }

}
